/*************************************************************************
	> File Name: P1102-2.cpp
	> Author: 
	> Mail: 
	> Created Time: 
 ************************************************************************/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n, c;
    cin >> n >> c;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    long long ans = 0;
    for (int i = 0, j = 0, k = 0; i < n; i++) {
        while (j < n && arr[j] - arr[i] < c) j++;
        while (k < n && arr[k] - arr[i] <= c) k++;
        if (arr[j] - arr[i] == c && k - 1 >= 0 && arr[k - 1] - arr[i] == c) {
            ans += k - j;
        }
    }
    cout << ans << endl;
    return 0;
}
